import express from 'express';
import { join } from 'path';
import router from './routes';
import { PORT } from './utils/config';
import { logger } from './middleware/logger';
import bodyParser from 'body-parser';

// 实例化express
const app = express();

// 限制传输的大小
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));

// 解析post的两个中间件
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// 输出静态目录
app.use('/public', express.static(join(__dirname, 'public')));

// 注册中间件
app.use(logger);

// 注册路由
app.use('/api',router);

app.listen(PORT, () => {
  console.log(`Example app listening on port ${PORT}`)
})